package com.lm.activiti.boot.cases;

/**
 * @author lm_jcf
 * @date 2022/3/3 11:06
 */
public class SynchronizerCase {

    public static void main(String[] args) {

        Instance i2 = new Instance(true);
        Instance i1 = new Instance(false);
        i2.add();
        i1.add();


    }

    public static class Instance{

        private boolean isLock;

        public Instance(boolean isLock) {
            this.isLock = isLock;
        }

        public void add(){
            synchronized (this) {

                if (isLock) {
                    try {
                        Thread.sleep(5000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }

                System.out.println(isLock+"输出");
            }
        }

    }

}
